﻿namespace PrismEx.SampleApp.Modules.ParameterizedNavigation
{
    using System;
    using System.ComponentModel.Composition;
    using System.Threading;

    using Microsoft.Practices.Prism.Commands;
    using Microsoft.Practices.Prism.Events;
    using Microsoft.Practices.Prism.MefExtensions.Modularity;
    using Microsoft.Practices.Prism.Modularity;

    using PrismEx.Events;
    using PrismEx.Events.Navigation;
    using PrismEx.Extensions;
    using PrismEx.SampleApp.Model;
    using PrismEx.SampleApp.Modules.ShowDialog;

    [ModuleExport(typeof(ParameterizedNavigationModule))]
    public class ParameterizedNavigationModule : IModule
    {
        private readonly IEventAggregator eventAggregator;

        [ImportingConstructor]
        public ParameterizedNavigationModule(IEventAggregator eventAggregator)
        {
            this.eventAggregator = eventAggregator;
        }

        public void Initialize()
        {
            this.eventAggregator.Publish(
                new InjectInstanceIntoRegionEvent
                    {
                        RegionName = "NavigationRegion",
                        Instance =
                            new
                                {
                                    Text = "Display Customers",
                                    Command =
                            new DelegateCommand<object>(
                            a =>
                                {
                                    this.eventAggregator.Publish(
                                        new NavigateUriEvent()
                                            {
                                                RegionName = "MainRegion",
                                                Uri = NavigationUriBuilder.ForType<ContainerView>()
                                            });        
                                    this.eventAggregator.Publish(
                                        new NavigateUriEvent()
                                            {
                                                RegionName = "CustomerListRegion",
                                                Uri = NavigationUriBuilder.ForType<ListView>()
                                            });
                                })
                                }

                    });
        }


    }
}
